/*
Copyright (C) Ariff Ehsan, Abdul Hadi Fikri

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*  Author : Ariff Ehsan
 *  Date   : July 11, 2009
 */


#ifndef __CXBEE_TYPE_H__
#define __CXBEE_TYPE_H__

#include <anos_boolean.h>

enum cxbee_api_id_enums {
	CXBEE_API_TXREQUEST = 0x01,
	
	CXBEE_API_ATCOMMAND = 0x08,
	
	CXBEE_API_ATRESPONSE = 0x88,
	CXBEE_API_TXSTATUS,
	CXBEE_API_MODEMSTATUS,
	
	CXBEE_API_RXPACKET = 0x81,
	
	CXBEE_BCAST_ADDR = 0xffff,
	
	CXBEE_COMMAND_TIMEOUT = 50, // milliseconds
};


typedef struct {
	uint8_t delimiter;
	uint8_t len[2];
	uint8_t api;
} atHeader_t;


typedef struct {
	uint8_t frameId;
	uint8_t dest[2];
	uint8_t option;
	uint8_t data[CXBEE_DATA_LENGTH];
} atTransmit_t;


typedef struct {
	uint8_t src[2];
	uint8_t rssi;
	uint8_t option;
	uint8_t data[CXBEE_DATA_LENGTH];
} atReceive_t;


typedef struct {
	uint8_t checksum;
} atFooter_t;


typedef union {
	atTransmit_t txdata;
	atReceive_t rxdata;
} cxbee_payload_t;


typedef struct {
	uint8_t tx_power; // set transmit power. value: 0 - 4 (refer xbee datasheet)
	BOOL ack;         // set false if no ack is required
} cxbee_metadata_t;


typedef struct {
	uint8_t header[sizeof(atHeader_t)];
	uint8_t data[sizeof(cxbee_payload_t)];
	uint8_t footer[sizeof(atFooter_t)];
	uint8_t metadata[sizeof(cxbee_metadata_t)];
} message_t;


#endif // __CXBEE_TYPE_H__